package com.zk.ppa.commom.result;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @author chenxiaolong
 * @since 2021年02月24日 11:21:00
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class Result<T> {
    private boolean success;
    private int code;
    private String message;
    private T data;

    public Result(ResultCode resultCode, T data) {
        this.success = resultCode.success;
        this.code = resultCode.code;
        this.message = resultCode.message;
        this.data = data;
    }

    public Result(ResultCode resultCode) {
        this.success = resultCode.success;
        this.code = resultCode.code;
        this.message = resultCode.message;
    }

    public static Result SUCCESS() {
        return new Result(ResultCode.SUCCESS);
    }

    public static Result FAIL(String message) {
        return new Result(ResultCode.FAIL).setMessage(message) ;
    }

    public static Result SYSTEM_ERROR() {
        return new Result(ResultCode.SERVER_ERROR);
    }

    public static Result PARAMETER_VERIFY_ERROR(){
        return new Result(ResultCode.PARAMETER_VERIFY_ERROR);
    }

    public static Result TOKEN_TIMEOUT_EXCEPTION(){
        return new Result(ResultCode.TOKEN_TIMEOUT_ERROR);
    }
}